#! /usr/bin/env python
from OWTFparser import ConfScanner, Reading, ReadingScanner
from xml.dom import minidom, Node

#from reading import *
#test 
#doc = minidom.parse("sensors_conf_xml.txt")
#x = ConfScanner(doc)
#print x.getSensors()

a = Reading()
a.SetMID("MID")
a.SetSID("SID")
a.SetLocation("LOCATION")
a.SetTime("TIME")
a.SetTemp("1")
a.SetHumid("2")
a.SetV1("3")
a.SetV2("4")

xdoc1 = a.toXML()
xdoc2 = a.toPrettyXML()
xdoc3 = a.toPrettyXML("  ")

doc1 = minidom.parseString(xdoc1)
doc2 = minidom.parseString(xdoc2)
doc3 = minidom.parseString(xdoc3)

x = ReadingScanner(doc1)
y = ReadingScanner(doc2)
z = ReadingScanner(doc3)
print x.getSensorData()
print y.getSensorData()
print z.getSensorData()


"""
<?xml version='1.0' encoding='utf-8'?>
<reading>
    <monitor>
        <monitor-name>mid</monitor-name>
        <sensor> 
            <sensor-name>sid</sensor-name>
            <location>location</location>
            <values> 
                <cron>datetime</cron>
                <temp>98.8</temp>
                <humid>30</humid>
                <V1>1</V1>
                <V2>1</V2>
            </values>
        </sensor>
    </monitor>
</reading>
"""

"""
doc = minidom.Document()
#create <reading>
reading = doc.createElement('reading')
doc.appendChild(reading)

#create <monitor>
monitor = doc.createElement('monitor')
reading.appendChild(monitor)

monitorID = doc.createElement('monitor-name')
monitorID.appendChild(doc.createTextNode('MID'))
monitor.appendChild(monitorID)

# create <sensor>
sensor = doc.createElement('sensor')
monitor.appendChild(sensor)
sensorID = doc.createElement('sensor-name')
sensorID.appendChild(doc.createTextNode('SID'))
sensor.appendChild(sensorID)
location = doc.createElement('location')
location.appendChild(doc.createTextNode('LOCATION'))
sensor.appendChild(location)

#create <values>
values = doc.createElement('values')
sensor.appendChild(values)
cron = doc.createElement('cron')
cron.appendChild(doc.createTextNode('datetime'))
values.appendChild(cron)
temp = doc.createElement('temp')
temp.appendChild(doc.createTextNode('98.0'))
values.appendChild(temp)
humid = doc.createElement('humid')
humid.appendChild(doc.createTextNode('30'))
values.appendChild(humid)

V1 = doc.createElement('V1')
V1.appendChild(doc.createTextNode('1'))
values.appendChild(V1)
V2 = doc.createElement('V2')
V2.appendChild(doc.createTextNode('2'))
values.appendChild(V2)

print doc.toprettyxml()
doc2 = minidom.parseString(doc.toprettyxml())
x = ReadingScanner(doc2)
print x.getSensorData()
print type(doc.toprettyxml())
"""